package com.kk.init;

import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.FactoryBean;

/**
 * 9. 工厂 Bean
 * <p>
 * .
 *
 * @author little_lunatic
 * @date 2023-08-10
 */
@Slf4j
//@Component
public class TestFactoryBean implements FactoryBean<TestFactoryBean.TestFactoryInnerBean> {
    @Override
    public TestFactoryInnerBean getObject() throws Exception {
        log.info("9.1 FactoryBean getObject getInstance = {}", TestFactoryBean.getInstance());
        log.info("9.1 FactoryBean getObject TestFactoryInnerBean.INSTANCE = {}", TestFactoryInnerBean.INSTANCE);
        return TestFactoryInnerBean.INSTANCE;
    }

    @SneakyThrows
    @Override
    public Class<?> getObjectType() {
        log.info("9.2 FactoryBean getObjectType {}.", TestFactoryBean.class);
        return TestFactoryInnerBean.class;
    }

    public static class TestFactoryInnerBean {
        private static final TestFactoryInnerBean INSTANCE = new TestFactoryInnerBean();
    }

    public static TestFactoryInnerBean getInstance() {
        return TestFactoryInnerBean.INSTANCE;
    }
}

